package com.example.springblogdemo.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.springblogdemo.Mapper.BlogInfoMapper;
import com.example.springblogdemo.Pojo.Response.BlogListResponse;
import com.example.springblogdemo.Pojo.dataObject.BlogInfo;
import com.example.springblogdemo.Service.BlogService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service("blogServiceImpl")
public class BlogServiceImpl implements BlogService {
    @Autowired
    private BlogInfoMapper blogInfoMapper;
    @Override
    public List<BlogListResponse> getList() {
        QueryWrapper<BlogInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(BlogInfo::getDeleteFlag,0);
        List<BlogInfo> bloginfos=blogInfoMapper.selectList(queryWrapper);
        List<BlogListResponse> blogListResponses=bloginfos.stream().map(bloginfo->{
            BlogListResponse blogListResponse=new BlogListResponse();
            BeanUtils.copyProperties(bloginfo,blogListResponse);
            return blogListResponse;
        }).collect(Collectors.toList());
        return blogListResponses;
    }
}
